package cn.uyunsky.platform.config.bean.combobox;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;

@XmlAccessorType(XmlAccessType.FIELD)
public class Combobox {

	@XmlAttribute
	private String id;

	@XmlElement(name = "sql")
	private String sql;

	@XmlElement(name = "entry")
	private List<Entry> entry= new ArrayList<Entry>();

    //在形成一个map对象,方便根据key来查找value
    private Map<String,String> mapdata = new HashMap<String,String>();

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public List<Entry> getEntry() {
		return entry;
	}

	public void setEntry(List<Entry> entry) {
		this.entry = entry;
        for (Entry e : entry) {
            mapdata.put(e.getKey(), e.getValue());
        }
	}

    public void addEntry(Entry entry) {
        this.entry.add(entry);
        mapdata.put(entry.getKey(), entry.getValue());
    }

	/**
	 * <p>Description: 是否查询combobox</p>
	 * 参数说明:
	 * @return 
	 */
	public boolean isQuery() {
		if (sql == null || "".equals(sql) || !sql.toLowerCase().contains("select")) {
			return false;
		} else {
			return true;
		}
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Combobox [id=");
		builder.append(id);
		builder.append(", sql=");
		builder.append(sql);
		builder.append(", entry=");
		builder.append(entry);
		builder.append("]");
		return builder.toString();
	}

}
